<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  
  <title>Java编程基础 | 奉孝的测开日记</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  
  
  
    <link rel="alternate" href="/blog/atom.xml" title="奉孝的测开日记" type="application/atom+xml">
  
  
    <link rel="shortcut icon" href="/blog/favicon.png">
  
  
    
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/typeface-source-code-pro@0.0.71/index.min.css">

  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
    
<link rel="stylesheet" href="/blog/fancybox/jquery.fancybox.min.css">

  
  
    
<link rel="stylesheet" href="/blog/localshare/css/share.css">

  
  
  
<meta name="generator" content="Hexo 5.4.2"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/blog/" id="logo">奉孝的测开日记</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/blog/" id="subtitle">开启自我改变的原动力</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        
          <a class="main-nav-link" href="/blog/."><i class="fa fa-home"></i> 首页</a>
        
          <a class="main-nav-link" href="/blog/archives/"><i class="fa fa-archive"></i> 归档</a>
        
          <a class="main-nav-link" href="/blog/about/"><i class="fa fa-user"></i> 关于</a>
        
      </nav>
    </div>
    <div id="search-form">
      <div id="result-mask" class="hide"></div>
      <label><input id="search-key" type="text" autocomplete="off" placeholder="搜索"></label>
      <div id="result-wrap" class="hide">
        <div id="search-result"></div>
      </div>
      <div class="hide">
        <template id="search-tpl">
          <div class="item">
            <a href="/{path}" title="{title}">
              <div class="title">{title}</div>
              <div class="time">{date}</div>
              <div class="tags">{tags}</div>
            </a>
          </div>
        </template>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-Java编程基础" class="h-entry article article-type-post" itemprop="blogPost" itemscope itemtype="https://schema.org/BlogPosting">
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="p-name article-title" itemprop="headline name">
      Java编程基础
    </h1>
  


      </header>
    
    <div class="article-meta">
      
      <span class="article-date">
  <i class="fa fa-date"></i>
  <time class="dt-published" datetime="2022-07-14T09:11:33.000Z" itemprop="datePublished">2022年07月14日</time>
</span>
      
  <div class="article-category">
    <i class="fa fa-classify"></i>
    <a class="article-category-link" href="/blog/categories/Java/">Java</a>
  </div>

      
        <span class="article-views">
  <i class="fa fa-views"></i>
  <i id="busuanzi_container_page_pv">
      <i id="busuanzi_value_page_pv"></i>
  </i>
</span>

      
      
<a href="/blog/2022/07/14/Java%E7%BC%96%E7%A8%8B%E5%9F%BA%E7%A1%80/#comments" class="article-comment-link">
  
    
    
    
    
    
  
  <i class="fa fa-commt"></i>
  留言
</a>


    </div>
    <div class="e-content article-entry" itemprop="articleBody">
      
        <h1 id="标识符"><a href="#标识符" class="headerlink" title="标识符"></a>标识符</h1><p>类名、变量名以及方法名都被称为标识符。规则如下：  </p>
<ul>
<li>以字母（A-Z 或者 a-z）,美元符（$）、或者下划线（_）开始</li>
<li>首字符之后可以是字母（A-Z 或者 a-z）,美元符（$）、下划线（_）或数字的任何字符组合</li>
<li>大小写敏感</li>
<li>关键字不能用作标识符</li>
</ul>
<h1 id="基本数据类型"><a href="#基本数据类型" class="headerlink" title="基本数据类型"></a>基本数据类型</h1><p>每种基本数据类型都有相应的包装类：Byte、Short、Integer、Long、Float、Double、Character。<br>包装类提供了面向对象的实现，比如二进制位数（Integer.SIZE）、最小值（Integer.MIN_VALUE）、最大值（Integer.MAX_VALUE）等</p>
<h2 id="整数类型"><a href="#整数类型" class="headerlink" title="整数类型"></a>整数类型</h2><table>
<thead>
<tr>
<th>类型</th>
<th>字节</th>
<th>位数</th>
<th>值域</th>
<th>默认值</th>
</tr>
</thead>
<tbody><tr>
<td>int</td>
<td>4</td>
<td>32</td>
<td>-2,147,483,648（-2^31）~ 2,147,483,647（2^31-1）</td>
<td>0</td>
</tr>
<tr>
<td>short</td>
<td>2</td>
<td>16</td>
<td>-32768（-2^15）~ 32767（2^15-1）</td>
<td>0</td>
</tr>
<tr>
<td>long</td>
<td>8</td>
<td>64</td>
<td>-9,223,372,036,854,775,808（-2^63）~ 9,223,372,036,854,775,807（2^63-1）</td>
<td>0L</td>
</tr>
<tr>
<td>byte</td>
<td>1</td>
<td>8</td>
<td>-128（-2^7）~ 127（2^7-1）</td>
<td>0</td>
</tr>
</tbody></table>
<h2 id="浮点类型"><a href="#浮点类型" class="headerlink" title="浮点类型"></a>浮点类型</h2><table>
<thead>
<tr>
<th>类型</th>
<th>字节</th>
<th>位数</th>
<th>默认值</th>
<th>精度</th>
</tr>
</thead>
<tbody><tr>
<td>float</td>
<td>4</td>
<td>32</td>
<td>0.0f</td>
<td>单</td>
</tr>
<tr>
<td>double</td>
<td>8</td>
<td>64</td>
<td>0.0d</td>
<td>双（是float的2倍</td>
</tr>
</tbody></table>
<h2 id="布尔和字符类型"><a href="#布尔和字符类型" class="headerlink" title="布尔和字符类型"></a>布尔和字符类型</h2><table>
<thead>
<tr>
<th>类型</th>
<th>字节</th>
<th>位数</th>
<th>值域</th>
<th>默认值</th>
</tr>
</thead>
<tbody><tr>
<td>boolean</td>
<td>1</td>
<td>8</td>
<td>true,false</td>
<td>false</td>
</tr>
<tr>
<td>char</td>
<td>2</td>
<td>16</td>
<td>所有字符</td>
<td>u0000</td>
</tr>
</tbody></table>
<h2 id="字面量"><a href="#字面量" class="headerlink" title="字面量"></a>字面量</h2><p>7 是一个int字面量，而7.0是double字面量。  </p>
<h2 id="类型转换"><a href="#类型转换" class="headerlink" title="类型转换"></a>类型转换</h2><h3 id="自动类型转换"><a href="#自动类型转换" class="headerlink" title="自动类型转换"></a>自动类型转换</h3><p>不会出现问题的类型转换，编程语言可以做自动类型转换，低精度向高精度转换</p>
<ul>
<li>精度顺序：double&gt;float&gt;long&gt;int&gt;short&gt;byte</li>
<li>char可以转为int：</li>
<li>char不可以转为short：虽然都是两个byte，但char为无符号数，值域超出了short可以表示的范围<h3 id="强制类型转换"><a href="#强制类型转换" class="headerlink" title="强制类型转换"></a>强制类型转换</h3>可能出现问题的类型转换，需要使用强制类型转换，比如高精度向低精度转换   <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">long a = 60; </span><br><span class="line">int b = 1; </span><br><span class="line">b = (int)a;</span><br><span class="line"></span><br><span class="line">int c = 65;</span><br><span class="line">char d = (char)c;</span><br></pre></td></tr></table></figure></li>
<li>会造成数据精度丢失  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">int a = 99;</span><br><span class="line">long b = 555555555555L;</span><br><span class="line">a = (int)b; // 此时a的值为1504774371</span><br></pre></td></tr></table></figure>
<h2 id="数值溢出"><a href="#数值溢出" class="headerlink" title="数值溢出"></a>数值溢出</h2></li>
<li>数值一旦计算溢出，结果将失去原有意义。比如两个正数会加出负数  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">int a = 2000000000;</span><br><span class="line">System.out.println(a+a); // 此时输出-294967296</span><br></pre></td></tr></table></figure></li>
<li><em>注意</em>* 实际上，JAVA中还存在另外一种基本类型 void，它也有对应的包装类 java.lang.Void，不过我们无法直接对它们进行操作</li>
</ul>
<h1 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h1><h2 id="算术运算符"><a href="#算术运算符" class="headerlink" title="算术运算符"></a>算术运算符</h2><p>+、-、*、/、%、++、–<br><strong>注意</strong><br>b = ++a 与 b = a++的区别，前者是先a+1再赋值给b，后者是先将a赋值给b,a再加1</p>
<h2 id="关系运算符"><a href="#关系运算符" class="headerlink" title="关系运算符"></a>关系运算符</h2><p>==、&gt;、&gt;=、&lt;、&lt;=、!=</p>
<h2 id="赋值运算符"><a href="#赋值运算符" class="headerlink" title="赋值运算符"></a>赋值运算符</h2><p>=、+=、-=、*=、/=、%=、&lt;&lt;=、&gt;&gt;=、&amp;=、|=、^=</p>
<h2 id="位运算符"><a href="#位运算符" class="headerlink" title="位运算符"></a>位运算符</h2><p>&amp;、|、^、～、&lt;&lt;、&gt;&gt;、&gt;&gt;&gt;<br>1、&lt;&lt; 左移，右边补0。左移没有带符号位一说，因为符号位在最左侧<br>2、&gt;&gt; 符号位不动，其余位右移，符号位后边补0，又称带符号右移<br>3、&gt;&gt;&gt; 符号位一起右移，左边补0，又称无符号右移</p>
<p><strong>技巧</strong><br>(~x) = -(x + 1)  </p>
<ul>
<li>^    如果相对应位值相同，则结果为0，否则为1 <h2 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符"></a>逻辑运算符</h2>&amp;&amp;、||、!<h2 id="条件运算符"><a href="#条件运算符" class="headerlink" title="条件运算符"></a>条件运算符</h2>条件运算符也被称为三元运算符。  <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">public class Test &#123;</span><br><span class="line">   public static void main(String[] args)&#123;</span><br><span class="line">      int a , b;</span><br><span class="line">      a = 10;</span><br><span class="line">      // 如果 a 等于 1 成立，则设置 b 为 20，否则为 30</span><br><span class="line">      b = (a == 1) ? 20 : 30;</span><br><span class="line">      System.out.println( &quot;Value of b is : &quot; +  b );</span><br><span class="line">   &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="instanceof-运算符"><a href="#instanceof-运算符" class="headerlink" title="instanceof 运算符"></a>instanceof 运算符</h2>该运算符用于操作对象实例，检查该对象是否是一个特定类型  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">String name = &quot;James&quot;;</span><br><span class="line">boolean result = name instanceof String; // 由于 name 是 String 类型，所以返回真</span><br></pre></td></tr></table></figure>
<h2 id="优先级"><a href="#优先级" class="headerlink" title="优先级"></a>优先级</h2>多用小括号把优先计算的表达式框起来</li>
</ul>
<h1 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h1><ul>
<li>什么是字符集（Charset）？<ul>
<li>字符集就是字符的集合。一般会包含一种语言的字符。比如GBK，是包含所有汉字字符的字符集。ASCII，是包含英文字符的字符集。</li>
<li>字符就是Java中的char,char就是character的简写</li>
</ul>
</li>
<li>什么是编码（Encoding）？<ul>
<li>char代表一个字符，char的本质也是数字。将数字映射到字符，就叫编码</li>
<li>将一个字符集映射到数字，就是给这个字符集编码。</li>
<li>有时间编码和字符集会混用</li>
</ul>
</li>
<li>常用的字符集<ul>
<li>ASCII码</li>
<li>Unicode,包含世界上所有常用字符。编码也有几种，UTF-8、UTF-16等</li>
<li>Unicode、GBK等常用的字符集都兼容ASCII</li>
</ul>
</li>
<li>Java中的字符集<ul>
<li>用UTF-16编码的Unicode</li>
<li>UTF-16用16个bit,即2个byte,这也是char占用2个byte的原因。</li>
</ul>
</li>
<li>转义符<ul>
<li>\n 换行</li>
<li>&quot; 双引号</li>
<li>\t 制表符</li>
<li>\uXXXX unicode编码对应的字符</li>
</ul>
</li>
</ul>
<h1 id="代码块和变量作用域"><a href="#代码块和变量作用域" class="headerlink" title="代码块和变量作用域"></a>代码块和变量作用域</h1><h2 id="大括号括起来的就是代码块"><a href="#大括号括起来的就是代码块" class="headerlink" title="大括号括起来的就是代码块"></a>大括号括起来的就是代码块</h2><ul>
<li>有名字的代码块 if-else代码块、for循环代码块、main方法代码块</li>
<li>代码块也叫体，比如for循环体、main方法体</li>
<li>代码块可以嵌套<h2 id="作用域和命名空间"><a href="#作用域和命名空间" class="headerlink" title="作用域和命名空间"></a>作用域和命名空间</h2></li>
</ul>
<h1 id="条件语句"><a href="#条件语句" class="headerlink" title="条件语句"></a>条件语句</h1><ul>
<li>if…else</li>
<li>switch case<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">switch(expression)&#123;</span><br><span class="line">    case value :</span><br><span class="line">       //语句</span><br><span class="line">       break; //可选</span><br><span class="line">    case value :</span><br><span class="line">       //语句</span><br><span class="line">       break; //可选</span><br><span class="line">    //你可以有任意数量的case语句</span><br><span class="line">    default : //可选</span><br><span class="line">       //语句</span><br><span class="line">&#125;</span><br><span class="line">```  </span><br><span class="line">规则：  </span><br><span class="line">* switch 语句中的变量类型可以是： byte、short、int 或者 char。从 Java SE 7 开始，switch 支持字符串 String 类型了，同时 case 标签必须为字符串常量或字面量</span><br><span class="line">* case 语句中的值的数据类型必须与变量的数据类型相同，而且只能是常量或者字面常量</span><br><span class="line">* 当变量的值与 case 语句的值相等时，那么 case 语句之后的语句开始执行，直到 break 语句出现才会跳出 switch 语句</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">循环</span></span><br><span class="line">* for</span><br><span class="line">* while</span><br><span class="line">* do...while</span><br><span class="line">```shell</span><br><span class="line">do &#123;</span><br><span class="line">       //代码语句</span><br><span class="line">&#125;while(布尔表达式);</span><br></pre></td></tr></table></figure>
<h1 id="控制台输入"><a href="#控制台输入" class="headerlink" title="控制台输入"></a>控制台输入</h1></li>
<li>in.nextLine() 从命令行读取一行字符串</li>
<li>in.nextInt() 从命令行读取一个正整数<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Scanner in = new Scanner(System.in);</span><br><span class="line">System.out.println(&quot;请问你的名字是？&quot;);</span><br><span class="line">String str = in.nextLine();</span><br><span class="line">System.out.println(str + &quot;，你好。&quot;);</span><br><span class="line">System.out.println(&quot;请问你几岁了？&quot;);</span><br><span class="line">int age = in.nextInt();</span><br><span class="line">System.out.println(&quot;好的，&quot; + str + age + &quot;岁了。&quot;);</span><br></pre></td></tr></table></figure>
<h1 id="循环、判断实战"><a href="#循环、判断实战" class="headerlink" title="循环、判断实战"></a>循环、判断实战</h1></li>
<li>猜数字：生成一个指定范围内的随机正整数，从命令行读取一个整数，如果相同就猜中  </li>
<li>要求：  <ul>
<li>固定随机数的范围</li>
<li>支持猜测次数，指定次数内没猜对，就算失败</li>
<li>可以退出游戏</li>
<li>输出剩余的猜测次数</li>
<li>未猜中，提示猜测数目比实际数目小还是大</li>
<li>游戏结束后，输出猜数字游戏的统计</li>
<li>没有猜中，输出这次的目标数字</li>
<li>可以设置随机数的范围，可以设置最大猜测次数<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line">Scanner in = new Scanner(System.in);</span><br><span class="line">// 游戏设置</span><br><span class="line">int rangeStart = 1;</span><br><span class="line">int rangeEnd = 8;</span><br><span class="line">int guessTotal = 5;</span><br><span class="line">// 游戏统计</span><br><span class="line">int totalGameCount = 0;</span><br><span class="line">int totalCorrectCount = 0;</span><br><span class="line">// 是否结束游戏</span><br><span class="line">boolean stopGame = false;</span><br><span class="line">while (!stopGame)&#123;</span><br><span class="line">    // 初始化本次游戏的变量</span><br><span class="line">    int guessLeft = guessTotal;</span><br><span class="line">    int mod = rangeEnd - rangeStart;</span><br><span class="line">    double randNum = Math.random();</span><br><span class="line">    int num = ((int) (randNum * rangeEnd * 100)) % mod;</span><br><span class="line">    num += rangeStart;</span><br><span class="line">    if (num &lt;= rangeStart) &#123;</span><br><span class="line">        num = rangeStart + 1;</span><br><span class="line">    &#125;</span><br><span class="line">    if (num &gt;= rangeEnd) &#123;</span><br><span class="line">        num = rangeEnd - 1;</span><br><span class="line">    &#125;</span><br><span class="line">    System.out.println(&quot;=================== 猜 数 字 ===================&quot;);</span><br><span class="line">    System.out.println(&quot;目标数已经生成，数字在&quot; + rangeStart + &quot;到&quot; + rangeEnd + &quot;之间，&quot; +</span><br><span class="line">            &quot;不包括这两个数。共有&quot; + guessTotal + &quot;次猜测的机会。输入-1随时结束游戏。&quot;);</span><br><span class="line">    // 本次游戏是否开始了</span><br><span class="line">    boolean gameStart = true;</span><br><span class="line">    // 本次是否猜中数字</span><br><span class="line">    boolean guessCorrect = false;</span><br><span class="line">    while (guessLeft &gt; 0)&#123;</span><br><span class="line">        System.out.println(&quot;还有&quot; + guessLeft + &quot;次机会，请输入猜测的数字，回车确认&quot;);</span><br><span class="line">        int guessNum = in.nextInt();</span><br><span class="line">        // 输入-1，结束游戏</span><br><span class="line">        if (guessNum == -1) &#123;</span><br><span class="line">            stopGame = true;</span><br><span class="line">            break;</span><br><span class="line">        &#125;</span><br><span class="line">        if (guessNum &lt;= rangeStart || guessNum &gt;= rangeEnd) &#123;</span><br><span class="line">            System.out.println(&quot;请输入在&quot; + rangeStart + &quot;到&quot; + rangeEnd + &quot;之间，的数字，不包括这两个数。&quot;);</span><br><span class="line">            continue;</span><br><span class="line">        &#125;</span><br><span class="line">        // 只要至少猜过一次，就算玩过了。</span><br><span class="line">        if (gameStart) &#123;</span><br><span class="line">            totalGameCount++;</span><br><span class="line">            gameStart = false;</span><br><span class="line">        &#125;</span><br><span class="line">        // 可以用的猜测次数减1</span><br><span class="line">        guessLeft--;</span><br><span class="line">        if (guessNum == num) &#123;</span><br><span class="line">            totalCorrectCount++;</span><br><span class="line">            guessCorrect = true;</span><br><span class="line">            System.out.println(&quot;恭喜你猜对了！这次的数字就是&quot; + num +</span><br><span class="line">                    &quot;。本次你共猜了&quot; + (guessTotal - guessLeft) + &quot;次。&quot;);</span><br><span class="line">            break;</span><br><span class="line">        &#125; else if (guessNum &gt; num) &#123;</span><br><span class="line">            System.out.println(&quot;猜测的数字比目标数字大。&quot;);</span><br><span class="line">        &#125; else &#123;</span><br><span class="line">            System.out.println(&quot;猜测的数字比目标数字小。&quot;);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    if (!guessCorrect) &#123;</span><br><span class="line">        System.out.println(&quot;本次的目标数字是&quot; + num + &quot;。这次没有猜中。&quot;);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">System.out.println(&quot;共进行了&quot; + totalGameCount + &quot;次游戏，其中正确的为&quot; + totalCorrectCount + &quot;次&quot;);</span><br></pre></td></tr></table></figure>
<h1 id="数组"><a href="#数组" class="headerlink" title="数组"></a>数组</h1><h2 id="特点"><a href="#特点" class="headerlink" title="特点"></a>特点</h2></li>
</ul>
</li>
<li>相同类型的变量的集合</li>
<li>可以指定数组元素的个数，最多为int的最大值</li>
<li>元素有固定顺序</li>
<li>每个元素都有索引</li>
<li>如果说变量是一张有名字的纸，可以通过这个名字读写这个变量；数组则是有名字的本子，每页有一个页码，可以通过本子名字和页码读写数组元素<h2 id="创建数组"><a href="#创建数组" class="headerlink" title="创建数组"></a>创建数组</h2></li>
<li><code>dataType[] arrayRefVar = new dataType[arraySize];</code></li>
<li><code>dataType[] arrayRefVar = &#123;value0, value1, ..., valuek&#125;;</code><h2 id="循环数组"><a href="#循环数组" class="headerlink" title="循环数组"></a>循环数组</h2></li>
<li>基本循环<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">double[] myList = &#123;1.9, 2.9, 3.4, 3.5&#125;;</span><br><span class="line">// 打印所有数组元素</span><br><span class="line">for (int i = 0; i &lt; myList.length; i++) &#123;</span><br><span class="line">   System.out.println(myList[i] + &quot; &quot;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li>For-Each 循环<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">double[] myList = &#123;1.9, 2.9, 3.4, 3.5&#125;;</span><br><span class="line">// 打印所有数组元素</span><br><span class="line">for (double element:myList) &#123;</span><br><span class="line">   System.out.println(element);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="认识数组"><a href="#认识数组" class="headerlink" title="认识数组"></a>认识数组</h2></li>
<li>理解数组的名与实<ul>
<li>数组的实，是一块地址连续的内存，就像是编号连续的一沓白纸</li>
<li>数组的名，是这个连续内存的第一个内存的地址</li>
<li>数组的变量和基本变量一样，本身是个地址。但与基本变量不一样的是，这个地址的值是数组的名，也就是数组的第一个地址。</li>
</ul>
</li>
<li>数组 = 数组变量 + 数组的实体<ul>
<li>数组变量【索引】就是在数组原有地址的基础上，加上索引，获得想要的元素</li>
<li>索引从0开始，因为数组变量的地址就是数组第一个元素的地址，不需要加<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">int[] book = new int[5];</span><br><span class="line">System.out.println(book[0]);</span><br><span class="line"></span><br><span class="line">比如变量book的地址为8，new int[5]的第一个地址为20，这句语句就是将8指向20</span><br></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
<h2 id="数组的长度"><a href="#数组的长度" class="headerlink" title="数组的长度"></a>数组的长度</h2><ul>
<li>数组创建之后，长度不可以改变</li>
</ul>
<h2 id="多维数组"><a href="#多维数组" class="headerlink" title="多维数组"></a>多维数组</h2><ul>
<li>创建<code>String[][] str = new String[3][4];</code></li>
</ul>
<h2 id="数组实战"><a href="#数组实战" class="headerlink" title="数组实战"></a>数组实战</h2><ul>
<li>求某年最好成绩</li>
<li>求某年的平均成绩</li>
<li>求所有年份最好成绩</li>
<li>求某门课历年最好成绩<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br></pre></td><td class="code"><pre><span class="line">// 声明六个变量， 分别代表六门科目的成绩</span><br><span class="line">int YuWenIndex = 0;</span><br><span class="line">int ShuXueIndex = 1;</span><br><span class="line">int WaiYuIndex = 2;</span><br><span class="line">int WuLiIndex = 3;</span><br><span class="line">int HuaXueIndex = 4;</span><br><span class="line">int ShengWuIndex = 5;</span><br><span class="line"></span><br><span class="line">int totalScoreCount = 6;</span><br><span class="line"></span><br><span class="line">// 每门课的名字</span><br><span class="line">String[] names = new String[totalScoreCount];</span><br><span class="line">names[YuWenIndex] = &quot;语文&quot;;</span><br><span class="line">names[ShuXueIndex] = &quot;数学&quot;;</span><br><span class="line">names[WaiYuIndex] = &quot;外语&quot;;</span><br><span class="line">names[WuLiIndex] = &quot;物理&quot;;</span><br><span class="line">names[HuaXueIndex] = &quot;化学&quot;;</span><br><span class="line">names[ShengWuIndex] = &quot;生物&quot;;</span><br><span class="line"></span><br><span class="line">Scanner scanner = new Scanner(System.in);</span><br><span class="line"></span><br><span class="line">System.out.println(&quot;请输入共有多少年的成绩：&quot;);</span><br><span class="line"></span><br><span class="line">int yearCount = scanner.nextInt();</span><br><span class="line"></span><br><span class="line">double[][] scores = new double[yearCount][totalScoreCount];</span><br><span class="line"></span><br><span class="line">for (int i = 0; i &lt; yearCount; i++) &#123;</span><br><span class="line">    for (int j = 0; j &lt; totalScoreCount; j++) &#123;</span><br><span class="line">        scores[i][j] = 80 + Math.random() * 20;</span><br><span class="line">        System.out.println(&quot;第&quot; + (i + 1) + &quot;年&quot; + names[j] + &quot;成绩为：&quot; + scores[i][j]);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">boolean cont = true;</span><br><span class="line">while (cont) &#123;</span><br><span class="line">    System.out.println(&quot;请选择要进行的操作：&quot;);</span><br><span class="line">    System.out.println(&quot;1: 求某年最好成绩\n&quot; +</span><br><span class="line">            &quot;2: 求某年的平均成绩\n&quot; +</span><br><span class="line">            &quot;3: 求所有年份最好成绩\n&quot; +</span><br><span class="line">            &quot;4: 求某门课历年最好成绩&quot;);</span><br><span class="line"></span><br><span class="line">    int oprtId = scanner.nextInt();</span><br><span class="line"></span><br><span class="line">    int year = 0;</span><br><span class="line">    switch (oprtId) &#123;</span><br><span class="line">        case 1:</span><br><span class="line">            // 让用户输入指定的年份</span><br><span class="line">            System.out.println(&quot;请输入要计算第几年的最好成绩&quot;);</span><br><span class="line">            year = scanner.nextInt();</span><br><span class="line">            if (year &lt;= 0 || yearCount &lt; year) &#123;</span><br><span class="line">                System.out.println(&quot;非法的年份：&quot; + year);</span><br><span class="line">                cont = false;</span><br><span class="line">                break;</span><br><span class="line">            &#125;</span><br><span class="line">            year = year - 1;</span><br><span class="line">            // 指定年份的最好成绩的编号，开始假设是0</span><br><span class="line">            int bestOfYearScoreId = 0;</span><br><span class="line">            // 循环指定年份的成绩，找出最好的成绩</span><br><span class="line">            // TODO：如果有两门课的成绩一样，而且都是最高的，怎么办？</span><br><span class="line">            for (int i = 1; i &lt; totalScoreCount; i++) &#123;</span><br><span class="line">                if (scores[year][bestOfYearScoreId] &lt; scores[year][i]) &#123;</span><br><span class="line">                    bestOfYearScoreId = i;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println(&quot;第&quot; + (year + 1) + &quot;年成绩最好的科目为&quot; + names[bestOfYearScoreId] + &quot;，成绩为&quot; + scores[year][bestOfYearScoreId] + &quot;。&quot;);</span><br><span class="line">            break;</span><br><span class="line">        case 2:</span><br><span class="line">            System.out.println(&quot;请输入要计算第几年的平均成绩&quot;);</span><br><span class="line">            year = scanner.nextInt();</span><br><span class="line">            if (year &lt;= 0 || yearCount &lt; year) &#123;</span><br><span class="line">                System.out.println(&quot;非法的年份：&quot; + year);</span><br><span class="line">                cont = false;</span><br><span class="line">                break;</span><br><span class="line">            &#125;</span><br><span class="line">            year = year - 1;</span><br><span class="line">            double totalCountForAvg = 0;</span><br><span class="line">            for (int i = 0; i &lt; totalScoreCount; i++) &#123;</span><br><span class="line">                totalCountForAvg += scores[year][i];</span><br><span class="line">            &#125;</span><br><span class="line">            double avgOfYear = totalCountForAvg / totalScoreCount;</span><br><span class="line">            System.out.println(&quot;第&quot; + (year + 1) + &quot;年的平均成绩为&quot; + avgOfYear + &quot;。&quot;);</span><br><span class="line">            break;</span><br><span class="line">        case 3:</span><br><span class="line">            int bestYear = 0;</span><br><span class="line">            int bestScore = 0;</span><br><span class="line"></span><br><span class="line">            for (int i = 0; i &lt; yearCount; i++) &#123;</span><br><span class="line">                for (int j = 0; j &lt; totalScoreCount; j++) &#123;</span><br><span class="line">                    if (scores[bestYear][bestScore] &lt; scores[i][j]) &#123;</span><br><span class="line">                        bestYear = i;</span><br><span class="line">                        bestScore = j;</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println(&quot;所有年度最好成绩为第&quot; + (bestYear + 1) + &quot;年的&quot; + names[bestScore] + &quot;，成绩为&quot; + scores[bestYear][bestScore] + &quot;。&quot;);</span><br><span class="line">            break;</span><br><span class="line">        case 4:</span><br><span class="line">            System.out.println(&quot;请输入科目编号&quot;);</span><br><span class="line">            int subjectId = scanner.nextInt();</span><br><span class="line">            if (subjectId &lt;= 0 || totalScoreCount &lt; subjectId) &#123;</span><br><span class="line">                System.out.println(&quot;非法的科目编号：&quot; + subjectId);</span><br><span class="line">                cont = false;</span><br><span class="line">                break;</span><br><span class="line">            &#125;</span><br><span class="line">            subjectId = subjectId - 1;</span><br><span class="line">            year = 0;</span><br><span class="line">            for (int i = 1; i &lt; yearCount; i++) &#123;</span><br><span class="line">                if (scores[year][subjectId] &lt; scores[i][subjectId]) &#123;</span><br><span class="line">                    year = i;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            System.out.println(&quot;第&quot; + (year + 1) + &quot;年度&quot; + names[subjectId] + &quot;成绩最好，为&quot; + scores[year][subjectId] + &quot;。&quot;);</span><br><span class="line"></span><br><span class="line">            break;</span><br><span class="line">        default:</span><br><span class="line">            cont = false;</span><br><span class="line">            System.out.println(&quot;不支持：&quot; + oprtId + &quot;， 程序结束。&quot;);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ul>
<h1 id="变量"><a href="#变量" class="headerlink" title="变量"></a>变量</h1><h2 id="认识基本类型的变量"><a href="#认识基本类型的变量" class="headerlink" title="认识基本类型的变量"></a>认识基本类型的变量</h2><ul>
<li>变量的基本逻辑-有定才有变。在人看来，固定的是名字，变化的是名字对应的值。对计算机来说，固定的是地址，变化的是值。</li>
<li>理解计算机如何使用内存，完成变量的功能<ul>
<li>内存就是一堆白纸，只能通过页码编号访问，也就是内存地址</li>
<li>变量就是使用一个固定的地址加上这个地址对应的内存。计算机通过地址，读写地址对应的内存的值。完成变量的赋值和访问的功能。就好像恶意根据页码编号，在指定的白纸上写字，或者擦掉重新写。</li>
<li>变量的名就是地址，变量的实就是地址对应的内存的值</li>
</ul>
</li>
</ul>

        
            <div id="toc-article">
                
  <div class="widget-wrap" id="toc-wrap">
    <h3 class="widget-title"><i class="fa fa-toc"></i> 文章目录</h3>
    <div class="widget">
      <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%A0%87%E8%AF%86%E7%AC%A6"><span class="toc-text">标识符</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-text">基本数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B4%E6%95%B0%E7%B1%BB%E5%9E%8B"><span class="toc-text">整数类型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%AE%E7%82%B9%E7%B1%BB%E5%9E%8B"><span class="toc-text">浮点类型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%83%E5%B0%94%E5%92%8C%E5%AD%97%E7%AC%A6%E7%B1%BB%E5%9E%8B"><span class="toc-text">布尔和字符类型</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AD%97%E9%9D%A2%E9%87%8F"><span class="toc-text">字面量</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-text">类型转换</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%8A%A8%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-text">自动类型转换</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BC%BA%E5%88%B6%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2"><span class="toc-text">强制类型转换</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E5%80%BC%E6%BA%A2%E5%87%BA"><span class="toc-text">数值溢出</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-text">运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%AE%97%E6%9C%AF%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-text">算术运算符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%B3%E7%B3%BB%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-text">关系运算符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%B5%8B%E5%80%BC%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-text">赋值运算符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%8D%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-text">位运算符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-text">逻辑运算符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%9D%A1%E4%BB%B6%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-text">条件运算符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#instanceof-%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-text">instanceof 运算符</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BC%98%E5%85%88%E7%BA%A7"><span class="toc-text">优先级</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-text">字符串</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BB%A3%E7%A0%81%E5%9D%97%E5%92%8C%E5%8F%98%E9%87%8F%E4%BD%9C%E7%94%A8%E5%9F%9F"><span class="toc-text">代码块和变量作用域</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%A7%E6%8B%AC%E5%8F%B7%E6%8B%AC%E8%B5%B7%E6%9D%A5%E7%9A%84%E5%B0%B1%E6%98%AF%E4%BB%A3%E7%A0%81%E5%9D%97"><span class="toc-text">大括号括起来的就是代码块</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%9C%E7%94%A8%E5%9F%9F%E5%92%8C%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4"><span class="toc-text">作用域和命名空间</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%9D%A1%E4%BB%B6%E8%AF%AD%E5%8F%A5"><span class="toc-text">条件语句</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%8E%A7%E5%88%B6%E5%8F%B0%E8%BE%93%E5%85%A5"><span class="toc-text">控制台输入</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%BE%AA%E7%8E%AF%E3%80%81%E5%88%A4%E6%96%AD%E5%AE%9E%E6%88%98"><span class="toc-text">循环、判断实战</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%95%B0%E7%BB%84"><span class="toc-text">数组</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%89%B9%E7%82%B9"><span class="toc-text">特点</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E6%95%B0%E7%BB%84"><span class="toc-text">创建数组</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BE%AA%E7%8E%AF%E6%95%B0%E7%BB%84"><span class="toc-text">循环数组</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AE%A4%E8%AF%86%E6%95%B0%E7%BB%84"><span class="toc-text">认识数组</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E7%BB%84%E7%9A%84%E9%95%BF%E5%BA%A6"><span class="toc-text">数组的长度</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%A4%9A%E7%BB%B4%E6%95%B0%E7%BB%84"><span class="toc-text">多维数组</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%95%B0%E7%BB%84%E5%AE%9E%E6%88%98"><span class="toc-text">数组实战</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%8F%98%E9%87%8F"><span class="toc-text">变量</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%AE%A4%E8%AF%86%E5%9F%BA%E6%9C%AC%E7%B1%BB%E5%9E%8B%E7%9A%84%E5%8F%98%E9%87%8F"><span class="toc-text">认识基本类型的变量</span></a></li></ol></li></ol>
    </div>
  </div>


            </div>
        
        
          <blockquote id="copyright">
              <p>原文链接: <a href="http://haohongbin.gitee.io/blog/2022/07/14/Java编程基础/">http://haohongbin.gitee.io/blog/2022/07/14/Java编程基础/</a></p>
              <p>版权声明: 转载请注明出处.</p>
          </blockquote>
        
      
    </div>
    <footer class="article-footer">
      
        <div class="article-tag-wrap">
          

          
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/blog/tags/%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" rel="tag">学习总结</a></li></ul>

          
    <div class="social-share">
      <span>分享到:</span>
    </div>



        </div>
      
      
        
<nav id="article-nav">
  
    <a href="/blog/2022/07/12/Hexo%E5%8D%9A%E5%AE%A2%E6%AD%A3%E6%96%87%E5%9B%BE%E7%89%87%E4%B8%8D%E6%98%BE%E7%A4%BA%E8%A7%A3%E5%86%B3%E6%96%B9%E6%B3%95/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">older</strong>
      <div class="article-nav-title">
        
          Hexo博客正文图片不显示解决方法
        
      </div>
    </a>
  
  
    <a href="/blog/2022/07/15/Java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">newer</strong>
      <div class="article-nav-title">
        
          Java面向对象编程
        
      </div>
    </a>
  
</nav>

      
      
        








      
    </footer>
  </div>
</article>
</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-posts"></i> 最新文章</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/blog/2023/03/14/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3%E5%88%97%E8%A1%A8%E5%92%8C%E5%85%83%E7%BB%84/">(no title)</a>
          </li>
        
          <li>
            <a href="/blog/2023/03/09/Java%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95Mock%E7%A5%9E%E5%99%A8/">Java单元测试Mock神器</a>
          </li>
        
          <li>
            <a href="/blog/2023/02/21/Pytest%E6%89%A7%E8%A1%8C%E7%94%A8%E4%BE%8B%E7%9A%84%E5%A4%9A%E7%A7%8D%E6%96%B9%E5%BC%8F/">Pytest执行用例的多种方式</a>
          </li>
        
          <li>
            <a href="/blog/2023/02/20/SQL%E6%9F%A5%E8%AF%A2%E5%9C%BA%E6%99%AF/">SQL查询场景</a>
          </li>
        
          <li>
            <a href="/blog/2023/01/18/MySQL%E5%91%BD%E4%BB%A4%E6%89%8B%E5%86%8C/">MySQL命令手册</a>
          </li>
        
      </ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-tag"></i> 标签云</h3>
    <div class="widget tagcloud">
      <a href="/blog/tags/MySQL/" style="font-size: 15px;">MySQL</a> <a href="/blog/tags/%E5%88%86%E4%BA%AB/" style="font-size: 15px;">分享</a> <a href="/blog/tags/%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95/" style="font-size: 10px;">单元测试</a> <a href="/blog/tags/%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" style="font-size: 20px;">学习总结</a> <a href="/blog/tags/%E8%87%AA%E5%8A%A8%E5%8C%96/" style="font-size: 10px;">自动化</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-classify"></i> 分类</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Java/">Java</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/Java%E6%A0%B8%E5%BF%83%E6%8A%80%E6%9C%AF/">Java核心技术</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/hexo%E5%8D%9A%E5%AE%A2/">hexo博客</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/vim/">vim</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E5%90%8E%E7%AB%AF/">后端</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%B5%8B%E8%AF%95/">测试</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E6%B5%8B%E8%AF%95%E8%BF%9B%E9%98%B6/">测试进阶</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-archive"></i> 归档</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2023/">2023年</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2022/">2022年</a><span class="archive-list-count">10</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title"><i class="fa fa-tag"></i> 标签</h3>
    <div class="widget">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/MySQL/" rel="tag">MySQL</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E5%88%86%E4%BA%AB/" rel="tag">分享</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95/" rel="tag">单元测试</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" rel="tag">学习总结</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/%E8%87%AA%E5%8A%A8%E5%8C%96/" rel="tag">自动化</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


  
    

  
</aside>
        
      </div>
      <a id="totop" href="#top"></a>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      <p>
        <a href="/blog/sitemap.xml">网站地图</a>
        <span> | </span><a href="/blog/atom.xml">订阅本站</a>
        <span> | </span><a href="/blog/about/">联系博主</a>
      </p>
      
        <p>
          <i class="fa fa-visitors"></i>
          <i id="busuanzi_container_site_uv"><i id="busuanzi_value_site_uv"></i></i>
          ，
          <i class="fa fa-views"></i>
          <i id="busuanzi_container_site_pv"><i id="busuanzi_value_site_pv"></i></i>
        </p>
      
      <p>
        <span>Copyright &copy; 2023 奉孝.</span>
        <span>Theme by <a href="https://github.com/chaooo/hexo-theme-BlueLake/" target="_blank">BlueLake.</a></span>
        <span>Powered by <a href="https://hexo.io/" target="_blank">Hexo.</a></span>
      </p>
    </div>
  </div>
</footer>

    </div>
  </div>
  
<script src="/blog/js/jquery-3.4.1.min.js"></script>


<script src="/blog/js/search.json.js"></script>


  
<script src="/blog/fancybox/jquery.fancybox.min.js"></script>




<script src="/blog/js/script.js"></script>






  
<script src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




  
    
<script src="/blog/localshare/js/social-share.js"></script>

    
<script src="/blog/localshare/js/qrcode.js"></script>

  
  



  

  

  

  

  

  

  

  
  





</body>
</html>